<?php
/**
 * Created by PhpStorm.
 * User: zjw
 * Date: 2018/3/8
 * Time: 下午6:04
 */

namespace backend\models;

use common\helpers\files\File;
use common\jobs\ImportGiftCardJob;
use common\models\Coupon;
use common\models\CouponCategory;
use yii\base\Model;
use yii\web\UploadedFile;
use yii;

class ExcelImport extends Model
{
    public $file_name;

    public $path;

    public function upload()
    {
        $uploader = UploadedFile::getInstance($this, 'file_name');
        $file = new File($uploader);
        $savePath = $file->uploadLocal();
        $this->path = File::getAbsPath($savePath);
        return $this->path;
    }

    public function import()
    {
        Yii::$app->queue->push(new ImportGiftCardJob([
            'path' => $this->path,
        ]));
        return true;
    }
}
